# encoding: utf-8

from PyQt5.Qt import *
from widget.daoru_page.target_init_page.mysql_target_init import MySqlInitPage
from widget.daoru_page.target_init_page.system_target_init import SystemInitPage
from widget.daoru_page.source_init_page.sqlserver_source_init import SqlServerInitPage
from widget.daoru_page.import_init_page.daoru_page_table import Sqlserver2EsTable
# from widget.daoru_page.import_init_page.daoru_page_table import Excl2EsTable
from widget.daoru_page.source_init_page.excl_source_init import ExclInitFunc
from widget.daoru_page.source_init_page.marc_source_init import MarcInitPage
from widget.daoru_page.source_init_page.choice_excl_sheet_window import ChoiceExclSheetWindow
from widget.daoru_page.source_init_page.noteexpress_source_init import NoteexpressInitFunc
# from widget.daoru_page.source_init_page.choice_noteexpress_type_window import ChoiceNoteexpressTypeWindow
from widget.my_window import MyWindow
from widget.info_box import *
import configparser
import json
from widget.db_init.peewee import testModel229_dp
from widget.db_init.configuration import sql_configuration as LM
from widget.db_init.sqlUtils.mysqlUtils import MySqlOp
import _thread
import time
import xlrd
import xlwt
from widget.utils.utils import RequestsOp
import requests
from widget.utils.utils import CfOp
from functools import partial
from widget.daoru_page.import_init_page.import_func.sqlserver_to_es_func import Sqlserver2Es
from widget.daoru_page.import_init_page.import_func.excl_to_es_func import Excl2Es
from widget.daoru_page.import_init_page.import_func.marc_to_es_func import Marc2Es
from widget.daoru_page.import_init_page.import_func.noteexpress_to_es_func import NoteExpress2Es


class DaoruTaskPage(QWidget):
    '''
    导入页面
    '''
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # self.setAttribute(Qt.WA_StyledBackground, True)
        self.my_parent = args[0]
        self.setParent(self.my_parent)

        self.wfstatus_dict_rb = {
            "": "",
            "N": "N(新增)",
            "C": "C(未完成)",
            "S": "S(成功)",
            "R": "R(重置)"
        }
        self.type_dict = {
            1: '资料',
            2: '实体',
            3: '附件'
        }

        self.task_type_url_dict = {
            'get': {
                '资料和附件': '/dataprocessingapi/systeminfo/getImportDataObjectTaskList.action',
                '基础表': '/dataprocessingapi/systeminfo/getImportEntityTaskList.action'
            },
            'retries': {
                '资料和附件': '/dataprocessingapi/dataimport/retriesimportDataobjecttask.action',
                '基础表': '/dataprocessingapi/dataimport/retriesimportEntitytask.action'
            },
            'delete': {
                '资料和附件': '/dataprocessingapi/dataimport/deletedataobjecttask.action',
                '基础表': '/dataprocessingapi/dataimport/deleteentitytask.action'
            }
        }

        # 获取当前系统的导入任务列表
        self.task_list = []

        # 设置控件名，用来统一显示隐藏控件
        self.setObjectName('the_base_page')

        # 基本页面,挂载到右侧操作控件
        self.setup_content_init()
        # 加载页面配置
        # self.init_page()

        # 初始化底部按钮
        # self.init_bottom_btns()

    # =========================== 界面 =========================================================================
    def setup_content_init(self):
        '''
        基本配置页面控件
        :return:
        '''
        # 页面初始化
        # 基础面板位置
        self.base_widget = QWidget(self)
        # print(self.parent().width(), self.parent().height())
        self.base_widget.setGeometry(20, 50, self.parent().width() - 20, self.parent().height() - 50)

        # 第一行 ---------------------------------------------------
        # 任务类型选框
        self.task_type_label = QLabel(text='任务类型：')
        self.task_type_label.setFixedWidth(80)
        self.task_type_combox = QComboBox()
        self.task_type_combox.setFixedWidth(300)
        self.task_type_combox.setView(QListView())  # 通过setView和全局qss设置行高
        self.task_type_combox.addItems(['资料和附件', '基础表'])
        self.task_type_combox.currentTextChanged.connect(lambda: self.refresh_table(pageno=0))

        # 流程状态选框
        self.task_state_label = QLabel(text='流程状态：')
        self.task_state_label.setFixedWidth(80)
        self.task_state_combox = QComboBox()
        self.task_state_combox.setFixedWidth(300)
        self.task_state_combox.setView(QListView())  # 通过setView和全局qss设置行高
        self.task_state_combox.addItems(['全部', 'N(新增)', 'C(未完成)', 'S(成功)', 'R(重置)'])
        self.task_state_combox.currentTextChanged.connect(lambda: self.refresh_table(pageno=0))

        # 第一行布局
        row0 = QHBoxLayout()
        row0.addWidget(self.task_type_label)
        row0.addWidget(self.task_type_combox)
        row0.addStretch(1)  # 站位分割
        row0.addWidget(self.task_state_label)
        row0.addWidget(self.task_state_combox)
        row0.addStretch(5)  # 站位分割

        # 第二行 ---------------------------------------------------
        # 任务表格
        # 第三行, 初始化表格 ---------------------------------------------------
        self.task_table = QTableWidget()
        self.task_table.setFixedWidth(920)
        self.task_table.setFixedHeight(500)
        # self.table1.setVerticalHeaderLabels(["第一列", "第二列"])
        # 设置表格每列的宽度
        # self.table1.setColumnWidth(2, 80)
        # print(field_list)
        # 刷新表格
        # self.refresh_table(pageno=0)

        row1 = QHBoxLayout()
        row1.addWidget(self.task_table)
        row1.addStretch(5)  # 站位分割

        # row1.addStretch(1)  # 站位分割

        self.line_label = QLabel(text='-'*120)
        rown = QHBoxLayout()
        rown.addWidget(self.line_label)

        # 行插入列，并调整间隔 ---------------------------------------------------
        vbox = QVBoxLayout()
        vbox.addStretch(1)  # 站位分割
        vbox.addLayout(row0)
        vbox.addStretch(1)  # 站位分割
        vbox.addLayout(rown)
        vbox.addStretch(1)  # 站位分割
        vbox.addLayout(row1)
        vbox.addStretch(3)  # 站位分割
        # vbox.addLayout(row2)
        # vbox.addStretch(10)  # 站位分割
        # vbox.addLayout(row_last)

        self.base_widget.setLayout(vbox)

        # 基础页面显示隐藏的方法 start -------------------------------------------
        # 初始化完成后先隐藏控件，等待按钮点击后显示
        self.close()
        # 基本配置按钮被点击时， 隐藏其他页面
        daoru_task_btn = self.parent().parent().findChild(QPushButton, 'daoru_task_history_btn')
        # 关闭其他基础页面的方法
        def close_other_pages():
            other_pages = self.parent().parent().findChildren(QWidget, 'the_base_page')
            for other_page in other_pages:
                other_page.close()
        # 触发关闭其他基础页面的按钮
        daoru_task_btn.clicked.connect(close_other_pages)
        # 触发获取任务列表方法
        daoru_task_btn.clicked.connect(lambda: self.refresh_table(pageno=0))
        # 显示对应页面
        daoru_task_btn.clicked.connect(self.show)
        daoru_task_btn.clicked.connect(self.my_parent.show)
        # 基础页面显示隐藏的方法 end -------------------------------------------

    # def init_bottom_btns(self):
    #     '''
    #     初始化底部按钮
    #     :return:
    #     '''
    #     self.enter_btn = QPushButton(parent=self, text='保存配置')
    #     self.enter_btn.resize(100, 40)
    #     self.enter_btn.move(self.parent().width() - 300, self.parent().height() - 100)
    #
    #     # 点击确定将 客户 和 系统类型 挂载到全局
    #     # self.enter_btn.clicked.connect(self.save_base_init)

    def show_task_detail_page(self, RUID):
        '''
        任务详情页
        :return:
        '''
        self.custom_box = CustomBox('任务详情页', width=500, height=350)
        self.custom_box.add_sys_msg_widget = QWidget(self.custom_box)
        self.custom_box.add_sys_msg_widget.setGeometry(50, 50, self.custom_box.width() - 100,
                                                       self.custom_box.height() - 100)

        # 任务的全部信息都在这儿啦tmd
        task_dict = self.get_task_detail_msg(RUID)
        if not task_dict:
            self.add_sys_msg_label1 = QLabel('获取不到任务')
            row0 = QHBoxLayout()
            row0.addWidget(self.add_sys_msg_label1)
            vbox = QVBoxLayout()
            vbox.addLayout(row0)
        else:
            task_type = self.get_task_type(task_dict['RUID'])

            self.add_sys_msg_label_1_a = QLabel('任务名: ')
            self.add_sys_msg_label_1_b = QLabel(task_dict['name'])
            # self.label.setGeometry(QRect(328, 240, 329, 27 * 4))
            self.add_sys_msg_label_1_b.setWordWrap(True)
            self.add_sys_msg_label_1_b.setAlignment(Qt.AlignTop)
            self.add_sys_msg_label_2_a = QLabel('任务重置次数: ')
            self.add_sys_msg_label_2_b = QLabel(str(task_dict['retriesnumber']))
            self.add_sys_msg_label_3_a = QLabel('成功数: ')
            self.add_sys_msg_label_3_b = QLabel(str(task_dict['successcount']) if task_type != 3 else str(task_dict['successfilecount']))
            self.add_sys_msg_label_4_a = QLabel('失败数: ')
            self.add_sys_msg_label_4_b = QLabel(str(task_dict['errorcount']) if task_type != 3 else str(task_dict['errorfilecount']))
            self.add_sys_msg_label_5_a = QLabel('创建时间: ')
            self.add_sys_msg_label_5_b = QLabel(task_dict['createtime'])
            self.add_sys_msg_label_6_a = QLabel('修改时间: ')
            self.add_sys_msg_label_6_b = QLabel(task_dict['modifytime'])
            self.add_sys_msg_label_7_a = QLabel('结束时间: ')
            self.add_sys_msg_label_7_b = QLabel(task_dict['finishtime'])
            self.add_sys_msg_label_8_a = QLabel('数据来源: ')
            self.add_sys_msg_label_8_b = QLabel(task_dict['source_dict']['name'])


            row0 = QHBoxLayout()
            row0.addWidget(self.add_sys_msg_label_1_a)
            row0.addWidget(self.add_sys_msg_label_1_b)
            row1 = QHBoxLayout()
            row1.addWidget(self.add_sys_msg_label_2_a)
            row1.addWidget(self.add_sys_msg_label_2_b)
            row2 = QHBoxLayout()
            row2.addWidget(self.add_sys_msg_label_3_a)
            row2.addWidget(self.add_sys_msg_label_3_b)
            row3 = QHBoxLayout()
            row3.addWidget(self.add_sys_msg_label_4_a)
            row3.addWidget(self.add_sys_msg_label_4_b)
            row4 = QHBoxLayout()
            row4.addWidget(self.add_sys_msg_label_5_a)
            row4.addWidget(self.add_sys_msg_label_5_b)
            row5 = QHBoxLayout()
            row5.addWidget(self.add_sys_msg_label_6_a)
            row5.addWidget(self.add_sys_msg_label_6_b)
            row6 = QHBoxLayout()
            row6.addWidget(self.add_sys_msg_label_7_a)
            row6.addWidget(self.add_sys_msg_label_7_b)
            row7 = QHBoxLayout()
            row7.addWidget(self.add_sys_msg_label_8_a)
            row7.addWidget(self.add_sys_msg_label_8_b)

            vbox = QVBoxLayout()
            vbox.addStretch(1)  # 站位分割
            vbox.addLayout(row0)
            vbox.addStretch(1)  # 站位分割
            vbox.addLayout(row1)
            vbox.addStretch(1)  # 站位分割
            vbox.addLayout(row2)
            vbox.addStretch(1)  # 站位分割
            vbox.addLayout(row3)
            vbox.addStretch(1)  # 站位分割
            vbox.addLayout(row4)
            vbox.addStretch(1)  # 站位分割
            vbox.addLayout(row5)
            vbox.addStretch(1)  # 站位分割
            vbox.addLayout(row6)
            vbox.addStretch(1)  # 站位分割
            vbox.addLayout(row7)
            vbox.addStretch(1)  # 站位分割

        self.custom_box.add_sys_msg_widget.setLayout(vbox)

        # 点击确定创建新 系统信息
        self.custom_box.enter_btn.close()
        self.custom_box.cancel_btn.setText('确定')

        self.custom_box.show()

    # =========================== 业务 =========================================================================
    def refresh_table(self, pageno):
        '''
        刷新任务表格
        :return:
        '''
        print('刷新表格')
        self.task_table.clear()

        # 设置表格的列数为2列
        self.task_table.setColumnCount(9)
        self.task_table.setColumnWidth(0, 125)
        self.task_table.setColumnWidth(1, 105)
        self.task_table.setColumnWidth(2, 105)
        self.task_table.setColumnWidth(3, 80)
        self.task_table.setColumnWidth(4, 80)
        self.task_table.setColumnWidth(5, 135)
        self.task_table.setColumnWidth(6, 70)
        self.task_table.setColumnWidth(7, 80)
        self.task_table.setColumnWidth(8, 80)
        self.task_table.setHorizontalHeaderLabels([
            "任务号",
            "任务名称",
            "来源名称",
            "任务类型",
            "状态",
            "创建时间",
            "操作1",
            "操作2",
            "操作3"
        ])

        task_type = self.task_type_combox.currentText()
        task_state = self.task_state_combox.currentText()
        res = self.get_import_task_history(task_type, task_state, pageno)

        # print('task_res: {0}'.format(res))
        if not res:
            return

        self.task_list = res['returnvalue']['recordlist']
        self.task_table.setRowCount(len(self.task_list))
        for i, js_dict in enumerate(self.task_list):
            RUID = str(js_dict['RUID'])
            wfstatus = str(js_dict['wfstatus']) if 'wfstatus' in js_dict else ''
            self.task_table.setItem(i, 0, QTableWidgetItem(RUID))
            self.task_table.setItem(i, 1, QTableWidgetItem(str(js_dict['name']) if 'name' in js_dict else ''))
            # 任务的全部信息都在这儿啦tmd
            task_dict = self.get_task_detail_msg(RUID)
            self.task_table.setItem(i, 2, QTableWidgetItem(task_dict['source_dict']['name']))
            self.task_table.setItem(i, 3, QTableWidgetItem(self.type_dict[self.get_task_type(RUID)]))
            self.task_table.setItem(i, 4, QTableWidgetItem(self.wfstatus_dict_rb[wfstatus]))
            self.task_table.setItem(i, 5, QTableWidgetItem(str(js_dict['createtime'])))

            detail_btn = QPushButton('详情')
            detail_btn.clicked.connect(partial(self.show_task_detail_page, RUID))
            self.task_table.setCellWidget(i, 6, detail_btn)

            if wfstatus and (wfstatus == 'N' or wfstatus == 'R'):
                push_btn = QPushButton('启动任务')
                push_btn.clicked.connect(partial(self.start_import, RUID))
                # push_btn.clicked.connect()
                self.task_table.setCellWidget(i, 7, push_btn)
            if wfstatus and wfstatus == 'C':
                push_btn = QPushButton('重置任务')
                push_btn.clicked.connect(partial(self.retries_task, RUID))
                self.task_table.setCellWidget(i, 7, push_btn)

            delete_btn = QPushButton('删除任务')
            delete_btn.clicked.connect(partial(self.delete_task, RUID))
            self.task_table.setCellWidget(i, 8, delete_btn)

    def start_import(self, RUID):
        '''
        开始导入
        :return:
        '''
        self.info_box = ChoiceBox('确定启动任务吗？')
        def go():
            '''
            # sqlserver导入系统平台的方法
            :param source_dict:
            :param target_dict:
            :param table1:
            :return:
            '''
            # print('还tnd没写嘞')
            self.info_box.close()
            # 获取当前任务
            for task in self.task_list:
                if task['RUID'] == RUID:
                    fileinit = json.loads(task['fileinit'].replace('\\', '\\\\'))
                    operate_dict = fileinit['operate_dict']
                    source_dict = fileinit['source_dict']
                    target_dict = fileinit['target_dict']
                    related_field_dict = fileinit['related_field_dict'] if 'related_field_dict' in fileinit else None

                    # print('operate_dict: {0}'.format(operate_dict))
                    print('source_dict: {0}'.format(source_dict))
                    # print('target_dict: {0}'.format(target_dict))

                    # sqlserver来源的导入 ---------------- start -----------------------------------
                    if source_dict['name'] == 'sqlserver':
                        s2e = Sqlserver2Es(source_dict, target_dict)
                        # 选择导入资料
                        if target_dict['target_type'] == 1:
                            all_data = s2e.get_all_data(operate_dict)
                            s2e.start_import_ziliao(all_data, RUID, operate_dict, self.base_widget)
                        # 选择导入实体
                        if target_dict['target_type'] == 2:
                            all_data = s2e.get_all_data(operate_dict)
                            s2e.start_import_shiti(all_data, RUID, operate_dict, self.base_widget)
                        # 导入附件
                        if target_dict['target_type'] == 3:
                            all_data = s2e.get_all_data(operate_dict, related_field_dict)
                            s2e.start_import_fujian(all_data, RUID, operate_dict, self.base_widget, related_field_dict)
                    # sqlserver来源的导入 ---------------- end -----------------------------------

                    # excel来源的导入 ---------------- start -----------------------------------
                    if source_dict['name'] == 'excl':
                        ex2e = Excl2Es(source_dict, target_dict)
                        if target_dict['target_type'] == 1:
                            all_data = ex2e.get_all_data(source_dict['uni']['file_path'], source_dict['uni']['sheet_index'], operate_dict)
                            ex2e.start_import_ziliao(all_data, RUID, operate_dict, self.base_widget)
                        if target_dict['target_type'] == 2:
                            all_data = ex2e.get_all_data(source_dict['uni']['file_path'], source_dict['uni']['sheet_index'], operate_dict)
                            ex2e.start_import_shiti(all_data, RUID, operate_dict, self.base_widget)
                        if target_dict['target_type'] == 3:
                            all_data = ex2e.get_all_data(source_dict['uni']['file_path'], source_dict['uni']['sheet_index'], operate_dict, related_field_dict)
                            ex2e.start_import_fujian(all_data, RUID, operate_dict, self.base_widget, related_field_dict)
                    # excel来源的导入 ---------------- end -----------------------------------

                    # noteexpress来源的导入 ---------------- start -----------------------------------
                    if source_dict['name'] == 'noteexpress':
                        ne2e = NoteExpress2Es(source_dict, target_dict)
                        all_data = ne2e.get_all_data(source_dict['uni']['file_path'], operate_dict)
                        ne2e.start_import_ziliao(all_data, RUID, operate_dict, self.base_widget)
                    # noteexpress来源的导入 ---------------- end -----------------------------------

                    # marc来源的导入 ---------------- start -----------------------------------
                    if source_dict['name'] == 'marc':
                        mar2e = Marc2Es(source_dict, target_dict)
                        # marc文件读取非常耗时，所以get_all_data会创建线程单独执行读取，并在读取完成后自动调用start_import_ziliao导入线程，
                        # 因此此处只需要调用 get_all_data 方法，并将 start_import_ziliao 方法所需的参数一并传入即可即可
                        mar2e.get_all_data(source_dict['uni']['file_path'], operate_dict, RUID, self.base_widget)
                    # marc来源的导入 ---------------- end -----------------------------------

        self.info_box.enter_btn.clicked.connect(go)
        self.info_box.show()

    def delete_task(self, RUID):
        '''
        删除任务
        :param RUID:
        :return:
        '''
        def go():
            task_type = self.task_type_combox.currentText()
            url = qApp.cx_es_db_ip + self.task_type_url_dict['delete'][task_type]
            print(url)
            # url = qApp.cx_es_db_ip + '/dataprocessingapi/dataimport/deletedataobjecttask.action'
            params = {
                'RUID': RUID
            }
            res = requests.get(url, params=params, timeout=1)
            if res.status_code != 200:
                self.info_box = InfoBox('删除任务失败，状态码：{0}'.format(res.status_code))
                self.info_box.show()
                return

            res = json.loads(res.text)
            if res['cxajaxrc'] != '0':
                self.info_box = InfoBox(res['cxajaxerrmsg'])
                self.info_box.show()
                return

            # 删除后刷新表
            self.refresh_table(pageno=0)

            self.info_box = InfoBox('删除任务成功')
            self.info_box.show()

        self.info_box = ChoiceBox('确定要删除任务吗？')
        self.info_box.enter_btn.clicked.connect(go)
        self.info_box.show()

    def retries_task(self, RUID):
        '''
        重置任务
        :return:
        '''
        def go():
            res = self.retries_task_func(RUID)
            if res.status_code != 200:
                self.info_box = InfoBox('重置任务失败，状态码：{0}'.format(res.status_code))
                self.info_box.show()
                return

            res = json.loads(res.text)
            if res['cxajaxrc'] != '0':
                self.info_box = InfoBox(res['cxajaxerrmsg'])
                self.info_box.show()
                return

            # 刷新表
            self.refresh_table(pageno=0)

            self.info_box = InfoBox('重置任务成功')
            self.info_box.show()

        self.info_box = ChoiceBox('确定要重置任务吗？')
        self.info_box.enter_btn.clicked.connect(go)
        self.info_box.show()

    def retries_task_func(self, RUID):
        task_type = self.task_type_combox.currentText()
        url = qApp.cx_es_db_ip + self.task_type_url_dict['retries'][task_type]
        print(url)
        # url = qApp.cx_es_db_ip + '/dataprocessingapi/dataimport/retriesimportDataobjecttask.action'
        params = {
            'taskruid': RUID
        }
        res = requests.get(url, params=params, timeout=1)
        print('任务已重置：{0}'.format(res.text))
        return res

    def get_task_type(self, RUID):
        '''
        获取导入任务类型 资料 实体 或者 附件
        :return:
        '''
        type_code = 1 if self.task_type_combox.currentIndex() == 0 else 2
        if type_code == 1:
            for task in self.task_list:
                if task['RUID'] == RUID:
                    fileinit = json.loads(task['fileinit'].replace('\\', '\\\\'))
                    type_code = 1 if (not 'related_field_dict' in fileinit or not fileinit['related_field_dict']) else 3
        return type_code

    def get_task_detail_msg(self, RUID):
        '''
        展示任务详细信息
        :return:
        '''
        for task in self.task_list:
            if task['RUID'] == RUID:
                # operate_dict = fileinit['operate_dict']
                # source_dict = fileinit['source_dict']
                # target_dict = fileinit['target_dict']
                # related_field_dict = fileinit['related_field_dict'] if 'related_field_dict' in fileinit else None
                #
                # createtime = task['createtime']
                # modifytime = task['modifytime']
                # wfstatus = self.wfstatus_dict_rb[task['wfstatus']]
                # name = task['name']
                # RUID = task['RUID']
                # successcount = task['successcount']
                # errorcount = task['errorcount']
                # successfilecount = task['successfilecount']
                # errorfilecount = task['errorfilecount']
                # repeatcount = task['repeatcount']
                # finishtime = task['finishtime']
                # retriesnumber = task['retriesnumber']

                # print(operate_dict)
                # print(source_dict)
                # print(target_dict)
                # print(related_field_dict)
                print('task: {0}'.format(task))

                fileinit = json.loads(task['fileinit'].replace('\\', '\\\\'))

                task_dict = {
                    'createtime': task['createtime'],
                    'modifytime': task['modifytime'],
                    'wfstatus': self.wfstatus_dict_rb[task['wfstatus']],
                    'name': task['name'] if 'name' in task else None,
                    'RUID': task['RUID'],
                    'successcount': task['successcount'],
                    'errorcount': task['errorcount'],
                    'successfilecount': task['successfilecount'] if 'successfilecount' in fileinit else None,
                    'errorfilecount': task['errorfilecount'] if 'errorfilecount' in fileinit else None,
                    'repeatcount': task['repeatcount'],
                    'finishtime': task['finishtime'] if 'finishtime' in task else None,
                    'retriesnumber': task['retriesnumber'],
                    'operate_dict': fileinit['operate_dict'],
                    'target_dict': fileinit['target_dict'],
                    'source_dict': fileinit['source_dict'],
                    'related_field_dict': fileinit['related_field_dict'] if 'related_field_dict' in fileinit else None,
                }
                # print(task_dict[])
                return task_dict
        return None

    def get_import_task_history(self, task_type, task_state, pageno, pagesize=99999):
        '''
        获取导入任务list
        task_type ： (实体 / 资料和附件)
        task_state ： 流程状态
        pageno ： 当前页码
        pagesize ： 当前页大小
        :return:
        '''
        # task_type_url_dict = {
        #     '资料和附件': '/dataprocessingapi/systeminfo/getImportDataObjectTaskList.action',
        #     '基础表': '/dataprocessingapi/systeminfo/getImportEntityTaskList.action'
        # }
        wfstatus_dict = {
            "全部": "",
            "N(新增)": "N",
            "C(未完成)": "C",
            "S(成功)": "S",
            "R(重置)": "R"
        }

        url = qApp.cx_es_db_ip + self.task_type_url_dict['get'][task_type]
        print(url)
        params = {
            "pageno": pageno,
            "pagesize": pagesize,
            # "wfstatus": wfstatus_dict[task_state]
        }
        if wfstatus_dict[task_state]:
            params["wfstatus"] = wfstatus_dict[task_state]

        try:
            res = requests.get(url, params=params, timeout=1)
            if res.status_code != 200:
                self.info_box = InfoBox('导入任务获取失败，状态码：{0}'.format(res.status_code))
                self.info_box.show()
                return None
            res = json.loads(res.text)

            if res['cxajaxrc'] != '0':
                return None

            if res['cxajaxrc'] != '0' and res['cxajaxerrmsg']:
                self.info_box = InfoBox(res['cxajaxerrmsg'])
                self.info_box.show()
                return None

            task_list = res
            # print(shiti_task_list)
            print('task_list: {0}'.format(task_list))
            return task_list

        except Exception as e:
            print(e)
            return None
